package com.example.zbh.dsliao.ui.activty;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.example.zbh.dsliao.R;
import com.example.zbh.dsliao.model.entity.NetSongList;
import com.example.zbh.dsliao.service.DownLoaderService;
import com.example.zbh.dsliao.ui.adapter.DownLoadAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yaolin on 15/11/30.
 */
public class DownLoaderActivity extends BaseActivity implements View.OnClickListener, DownLoadAdapter.OnRemovClickListener {

    private ImageView img_back;

    private RecyclerView recyclerView;
    private GridLayoutManager manager;
    private String path = null;
    private String songName = null;

    private List<NetSongList> lists = new ArrayList<>();
    private DownLoadAdapter downLoadAdapter;



    @Override
    protected int getLayOut() {
        return R.layout.activity_downloadr;
    }

    @Override
    protected void initView() {

        img_back = (ImageView) findViewById(R.id.img_back);
        img_back.setOnClickListener(this);

        recyclerView = findeView(R.id.recyclerView);

    }

    @Override
    protected void initData() {
        NetSongList songList = (NetSongList) getIntent().getSerializableExtra("song");
        lists.add(songList);
        songName = songList.getName();
        path = songList.getAuditionList().get(0).getUrl();
        manager = new GridLayoutManager(this, 1);
        recyclerView.setLayoutManager(manager);
        Intent intent = new Intent();
        intent.setClass(this, DownLoaderService.class);
        intent.putExtra("url", path);
        intent.putExtra("name", songName);
        startService(intent);
        downLoadAdapter = new DownLoadAdapter(this);
        recyclerView.setAdapter(downLoadAdapter);
        downLoadAdapter.addData(lists);
        downLoadAdapter.setOnRemovClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.img_back:
                finish();
                break;
        }
    }

    @Override
    public void OnRemoveClick(List<NetSongList> list) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Intent intent = new Intent();
        intent.setClass(this, DownLoaderService.class);
        stopService(intent);
    }
}
